package com.qixin.modules.ea.controller;

import com.qixin.modules.ea.entity.EaAgencyReimbursement;
import com.qixin.modules.ea.mapper.EaAgencyReimbursementMapper;
import com.qixin.modules.ea.service.IEaAgencyReimbursementService;
import com.qixin.modules.ea.vo.EaAgencyReimbursementVo;
import com.qixin.modules.eaBasic.vo.IdVo;
import com.qixin.modules.eaBasic.vo.UserIdPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.EmptyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author:wly
 * @Date:2021/9/22
 * @Describtion: 代理设置
 */
@Api(tags="app代理设置")
@RestController
@RequestMapping("/app/api/eaAgencyReimbursement")
@Slf4j
public class ApiEaAgencyReimbursementController {
    @Autowired
    private IEaAgencyReimbursementService iEaAgencyReimbursementService;
    @Autowired
    private EaAgencyReimbursementMapper eaAgencyReimbursementMapper;

    /**
     * 查询代理设置列表
     *
     * @param userIdPageVo
     * @return Result
     */
    @ApiOperation(value="app代理设置列表-查询", notes="app代理设置列表-查询")
    @PostMapping(value = "/list")
    public Result<?> list(@RequestBody UserIdPageVo userIdPageVo) {
        Map<String,Object> resutlList = iEaAgencyReimbursementService.list(userIdPageVo);
        return Result.OK(resutlList);
    }

    /**
     * 新增代理设置
     *
     * @param eaAgencyReimbursementVo
     * @return Result
     */
    @AutoLog(value = "新增代理设置")
    @ApiOperation(value="新增代理设置", notes="新增代理设置")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody EaAgencyReimbursementVo eaAgencyReimbursementVo) {
        Map<String,Object> returnMap = iEaAgencyReimbursementService.add(eaAgencyReimbursementVo);
        if(returnMap.get("code").equals("-1")){
            return Result.error(EmptyUtil.checkNull(returnMap.get("message")));
        }else{
            return Result.OK(returnMap.get("message"));
        }
    }

    /**
     * 编辑代理设置
     *
     * @param eaAgencyReimbursementVo
     * @return Result
     */
    @AutoLog(value = "编辑代理设置")
    @ApiOperation(value="编辑代理设置", notes="编辑代理设置")
    @PostMapping(value = "/edit")
    public Result<?> edit(@RequestBody EaAgencyReimbursementVo eaAgencyReimbursementVo) {
        Map<String,Object> returnMap = iEaAgencyReimbursementService.edit(eaAgencyReimbursementVo);
        if(returnMap.get("code").equals("-1")){
            return Result.error(EmptyUtil.checkNull(returnMap.get("message")));
        }else{
            return Result.OK(returnMap.get("message"));
        }
    }

    /**
     * 删除代理设置
     *
     * @param idVo
     * @return Result
     */
    @AutoLog(value = "删除代理设置")
    @ApiOperation(value="删除代理设置", notes="删除代理设置")
    @PostMapping(value = "/deleteById")
    public Result<?> deleteById(@RequestBody IdVo idVo) {
        iEaAgencyReimbursementService.deleteById(idVo);
        return Result.OK("删除成功!");
    }

    /**
     * 查询代理设置详情
     *
     * @param idVo
     * @return Result
     */
    @ApiOperation(value="查询代理设置详情", notes="查询代理设置详情")
    @PostMapping(value = "/selectById")
    public Result<?> selectById(@RequestBody IdVo idVo) {
        String id = idVo.getId();
        EaAgencyReimbursement eaAgencyReimbursement = eaAgencyReimbursementMapper.selectById(id);
        if(eaAgencyReimbursement==null) {
            return Result.error("未找到对应数据");
        }
        Map<String,Object> returnMap = iEaAgencyReimbursementService.selectById(idVo);
        return Result.OK(returnMap);
    }


}
